package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.Random;

import org.testng.annotations.*;

import com.example.utils.SortedListOf;

public class ContactRemovalTests extends TestBase {

  @Test
  public void deleteSomeContact() throws Exception {
    app.navigateTo().mainPage();
    SortedListOf<ContactData> oldList = (SortedListOf<ContactData>) app.getHebirnateHelper().listContacts();
    Random rnd = new Random();
    int index = rnd.nextInt(oldList.size()-1);
    app.getContactHelper().deleteContact(index);
    if (wantToCheck()) {
    	if ("yes".equals(app.getProperty("check.db"))) {
    		assertThat(app.getModel().getContacts(), equalTo(app.getHebirnateHelper().listContacts()));
    	}
    	if ("yes".equals(app.getProperty("check.ui"))) {
    		assertThat(app.getModel().getContacts(), equalTo(app.getContactHelper().getUiContacts()));
    	}
    }	
  }
}
